<template>
  <div class='cartcontrol'>
    <transition name='move'>
      <div
        class='cart-decrease'
        v-show='food.count>0'
        @click.stop.prevent='decreaseCart'
      >
        <i class='iconfont decr-icon'>&#xe712;</i>
      </div>
    </transition>
    <div class='cart-count' v-show='food.count>0'>{{food.count}}</div>
    <div class='cart-add' @click.stop.prevent='addCart'>
      <i class='iconfont add-icon'>&#xe6e0;</i>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
export default {
  name: 'cartcontrol',
  props: {
    food: {
      type: Object
    }
  },
  methods: {
    addCart (event) {
      if (!event._constructed) {
        return
      }
      if (!this.food.count) {
        Vue.set(this.food, 'count', '1')
      } else {
        this.food.count++
      }
    },
    decreaseCart (event) {
      if (!event._constructed) {
        return
      }
      if (this.food.count) {
        this.food.count--
      }
    }
  }
}
</script>

<style lang='stylus' scoped>
  .cartcontrol
    font-size: 0
    .cart-decrease
      display:inline-block
      padding: 6px
      transition: all 0.4s linear
      .decr-icon
        display: inline-block
        line-height: 24px
        font-size: 24px
        color: rgb(0,160,220)
        vertical-align: top
      &.move-enter-active, &.move-leave-active
        transition: all 0.4s linear
        .decr-icon
          transition: all 0.4s linear
      &.move-enter, &.move-leave-to
        opacity: 0
        transform: translate3D(24px,0,0)
        .decr-icon
          transform: rotate(180deg)
    .cart-count
      display:inline-block
      font-size: 10px
      vertical-align: top
      line-height: 24px
      width: 12px
      text-align: center
      padding-top: 6px
      color: rgb(147,153,159)
    .cart-add
      display:inline-block
      padding: 6px
      .add-icon
        line-height: 24px
        font-size: 24px
        color: rgb(0,160,220)
        vertical-align: top
</style>
